package android.longs.study.user.dao.clas;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import android.longs.study.user.model.clas.JavaClassModel;
import android.longs.study.utils.H3Utils;

public class ClassModelDaoImple implements ClassModelDao{

    @Override
    public void addClass(JavaClassModel classModel) {
	Session currentSession = H3Utils.getCurrentSession();
	currentSession.save(classModel);
    }

    @Override
    public void updateClass(JavaClassModel classModel) {
	
	Session currentSession = H3Utils.getCurrentSession();
	currentSession.saveOrUpdate(classModel);
	
    }

    @Override
    public List<JavaClassModel> queryAllClass() {
	Session currentSession = H3Utils.getCurrentSession();
	String hql = "from JavaClassModel";
	Query createQuery = currentSession.createQuery(hql);
	List<JavaClassModel> list = createQuery.list();
	
	return list;
    }

    @Override
    public List<JavaClassModel> queryAllClass(int start, int end) {
	Session currentSession = H3Utils.getCurrentSession();
	String hql = "from JavaClassModel";
	//设置分页查询 
	Query createQuery = currentSession.createQuery(hql).setFirstResult(start).setMaxResults(10);
	
	List<JavaClassModel> list = createQuery.list();
	return list;
    }

    @Override
    public JavaClassModel queryFormID(String id) {
	Session currentSession = H3Utils.getCurrentSession();
	String hql ="from JavaClassModel c where c.id = "+id;
	JavaClassModel uniqueResult = (JavaClassModel) currentSession.createQuery(hql).uniqueResult();
	return uniqueResult;
    }

    @Override
    public JavaClassModel queryFormClassName(String name) {
	//session 
	Session currentSession = H3Utils.getCurrentSession();
	String hql ="from JavaClassModel c where c.className = "+name;
	JavaClassModel uniqueResult = (JavaClassModel) currentSession.createQuery(hql).uniqueResult();
	return uniqueResult;
    }

   
}
